package com.bit.demo.springbookdemo.model;

import com.bit.demo.springbookdemo.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
        private ResultCodeEnum code;//-1表示未登录 200表示成功 -2表示失败
        private String errMsg;
        private T data;

        public static <T> Result success(T data){
            Result result = new Result();
            result.setCode(ResultCodeEnum.SUCCESS);
            result.setErrMsg("");
            result.setData(data);
            return result;
        }

        public static Result error(String errMsg){
            Result result = new Result();
            result.setCode(ResultCodeEnum.FAIL);
            result.setErrMsg(errMsg);
            result.setData(null);
            return result;
        }

    public static <T>Result error(String errMsg, T data){
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }

    public static Result unLogin(){
        Result result = new Result();
        result.setCode(ResultCodeEnum.UN_LOGIN);
        result.setErrMsg("用户未登录");
        result.setData(null);
        return result;
    }
}
